<template>
  <div>
    <!-- <button @click="setToken()">设置token</button>
    <button @click="getTokens()">获取Token</button>
    <button @click="removeToken()">删除token</button> -->

    <!-- token:{{ getToken }} - - [{{ tokens }}]//

    <br > -->
    <h3>请使用漫步云端账号登录</h3>
    <form class="login-box">
      <div class="form-group">
        <label for="exampleInputEmail1">邮箱</label>
        <input type="email" class="form-control" v-model="email" placeholder="邮箱地址">
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">密码</label>
        <input type="password" class="form-control" v-model="password" placeholder="登陆密码">
      </div>
      <div class="checkbox">
        <label>
          <input type="checkbox"> 记住我
        </label>
      </div>
      <button type="button" class="btn btn-default" @click="login">登陆</button>
    </form>
  </div>
</template>
<script>
// import { updateToken } from '../vuex/actions'
// import { mapGetters, mapActions } from 'vuex'
// import { getToken } from '../vuex/getters'
import { fetchLogin } from '../service'
export default{
  data () {
    return {
      tokens: '',
      email: null,
      password: null
    }
  },
  methods: {
    // ...mapActions([
    //   'updateToken'
    // ]),
    setToken: function (token) {
      localStorage.token = token
    },
    getTokens: function () {
      this.tokens = localStorage.token
    },
    removeToken: function () {
      localStorage.token = ''
      this.tokens = ''
    },
    login: function () {
      fetchLogin({email: this.email, password: this.password}).then((token) => {
        this.setToken(token)
        alert('登陆成功')
        this.$router.push({name: 'User'})
      })
    }
  },
  computed: {
    // ...mapGetters([
    //   'getToken'
    // ])
  }
}

</script>
<style scoped>
  h3{
    margin-top: 30px;
    margin-bottom: 20px;
    text-align: center;
  }
  .login-box{
    width: 500px;
    margin: 0 auto;
    background: rgba(255,255,255,.8);
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 0 5px #ccc;
  }
</style>
